package code.google.jcontainer.test.constraint;

import code.google.jcontainer.AbstractContainer;
import code.google.jcontainer.ContainerFactory;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;

/**
 * @author <a href="mailto:jfox.young@gmail.com">Young Yang</a>
 * @create 2009-12-21 16:13:37
 */
public class SimpleTestCase2 {

    private static AbstractContainer simpleContainer;

    @BeforeClass
    public static void setup(){
        // get my simple container by name
        simpleContainer = ContainerFactory.scanPackages("code.google.jcontainer.test").getContainer("SimpleContainer");
    }

    @Test
    public void testSetAgeCorrect() {
        // get the simple component by name
        SimpleTestBean2 simpleUserBean = (SimpleTestBean2)simpleContainer.getComponent("SimpleTestBean2");
        simpleUserBean.setAge(99);
    }

    @Test(expected = ParameterConstraintException.class)
    public void testSetAgeWrong() {
        // get the simple component by name
        SimpleTestBean2 simpleUserBean = (SimpleTestBean2)simpleContainer.getComponent("SimpleTestBean2");
        simpleUserBean.setAge(101); // will throw ParameterConstraintException
    }

    @Test
    public void testGetAge() {
        // get the simple component by name
        SimpleTestBean2 simpleUserBean = (SimpleTestBean2)simpleContainer.getComponent("SimpleTestBean2");
        Assert.assertEquals(99, simpleUserBean.getAge());
    }

}